# To change this template, choose Tools | Templates
# and open the template in the editor.

__author__="martin"
__date__ ="$26.03.2011 11:01:01$"

from pysimplesoap.server import SoapDispatcher, SOAPHandler
from BaseHTTPServer import HTTPServer
from soaplib.serializers.primitive import String
import urllib
from xml.dom import minidom


def addr2img(state,zipcode,city,street):
    "Please Add Values for State, ZipCode, City, Street"
    RQ_URL = 'http://local.yahooapis.com/MapsService/V1/mapImage?appid=YD-4g6HBf0_JX0yq2IsdnV1Ne9JTpKxQ3Miew--&street='+street+'&city='+city+'&state='+state+'&zip='+str(zipcode)
    url = RQ_URL
    dom = minidom.parse(urllib.urlopen(url))
    resulter = dom.firstChild
    returnurl = str(resulter.childNodes[0].toxml())
    
    return str(returnurl)

if __name__ == "__main__":
    dispatcher = SoapDispatcher(
        'map_dispatcher',
        location = "http://192.168.47.13:8008/",
        action = 'http://192.168.47.13:8008/', # SOAPAction
        namespace = "http://schemas.xmlsoap.org/wsdl/", prefix="ns0",
        trace = True,
        ns = True)

    # register the user function
    dispatcher.register_function('AddressToImage', addr2img,
        returns={'UrlResult': str},
        args={'state': str,'zipcode': int, 'city': str, 'street': str})

    print "Starting server..."
    httpd = HTTPServer(("", 8008), SOAPHandler)
    httpd.dispatcher = dispatcher
    httpd.serve_forever()

